package org.example.demo.publish;

import lombok.extern.slf4j.Slf4j;
import org.example.annotation.NotRecommend;
import org.example.annotation.NotThreadSafe;

import java.util.Arrays;

@Slf4j
@NotThreadSafe
@NotRecommend
public class UnsafePublish {

    private String[] states = {"a","b","c"};

    public String[] getStates() {
        return states;
    }

    public static void main(String[] args) {
        UnsafePublish unsafePublish = new UnsafePublish();
        log.info("{}", Arrays.toString(unsafePublish.getStates()));
        // 由于getStates是public的，所以unsafePublish对象中的states可以被别人修改！所以在多线程环境不安全
        unsafePublish.getStates()[0] = "d";
        log.info("{}", Arrays.toString(unsafePublish.getStates()));
    }
}
